package aes.general.test;

import java.io.IOException;
import java.util.ArrayList;

import aes.client.AesClient;
import aes.general.Exam;
import aes.general.Msg;
import aes.general.QuestionControl;
import aes.general.TeacherControl;
import fit.ActionFixture;

public class AddExam extends ActionFixture {
	
	
	private Exam x = new Exam();
	private ArrayList<String> qst = new ArrayList<String>();
	private ArrayList<String> pnt = new ArrayList<String>();
	private String CourseId;
	
	
	public void setExamSubject(String examSubject) {
		x.setExamSubject(examSubject);
	}

	public void setCourseId(String cur){
		CourseId = cur;	
	}
	
	public void setExamId(String examId) {
		x.setExamId(x.getExamSubject()+CourseId+examId);
	}
	
	public void setTeacherId(String teacherId) {
		x.setTeacherId(teacherId);
	}
	
	public void setDuration(Integer duration) {
		x.setDuration(duration);
	}
		
	public void setQuestion1(String questions) {
		qst.add(questions);
	}
	
	public void setQuestion2(String questions) {
		qst.add(questions);
	}
	
	public void setQuestion3(String questions) {
		qst.add(questions);
	}

	public void setQuestionPoints1(String questionPoints) {
		pnt.add(questionPoints);
	}
	
	public void setQuestionPoints2(String questionPoints) {
		pnt.add(questionPoints);
	}
	
	public void setQuestionPoints3(String questionPoints) {
		pnt.add(questionPoints);
	}
	
	public void setQuestion() {
		x.setQuestions(qst);
	}
	
	public void setQuestionPoints() {
		x.setQuestionPoints(pnt);
	}
	
	public void setComments(String comments) {
		x.setComments(comments);
	}
			
	public void SetCommentsVisible(boolean visible) {
		x.setVisible(visible);
	}
	
	
	
	public void saveExam()
	{		
		
		try {
			AesClient client = new AesClient("localhost", 3606);
			client.openConnection();
			Msg request = new Msg(x, "403");
			client.handleMessageFromClientUI(request);
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		qst.clear();
		pnt.clear();
		try {
			Thread.sleep(100);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public boolean checkExist()
	{
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		TeacherControl tc = new TeacherControl();
		return tc.isCheck();
		
	}
}

